//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.gc;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.GcRoomDao;
import com.aidong.model.wills.GcRoom;
import com.aidong.model.wills.GcRoomPK;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"gcRoom"})
public class GcRoomController extends BaseController {
    @Resource
    GcRoomDao gcRoomDao;

    public GcRoomController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("gc/room/list")).addObject("roomType", this.getTypeList("gcRoomType")).addObject("shopName", this.getTypeList("shopName"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "roomType",required = false) String roomType, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        cd.eq("shopCode", shopCode);
        if(!this.chkNull(status)) {
            cd.eq("status", status);
        } else {
            cd.gt("status", Integer.valueOf(0));
        }

        cd.eq("roomType", roomType);
        if(!this.chkNull(name)) {
            ConditionMap mv = new ConditionMap(1);
            mv.like("code", "%" + name + "%");
            mv.like("chName", "%" + name + "%");
            cd.addSub(mv);
        }

        this.gcRoomDao.queryPageList(pg, cd, (new OrderSet()).asc("code"));
        ModelAndView mv1 = new ModelAndView("gc/room/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("pg", pg);
        return mv1;
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        GcRoom room = new GcRoom();
        room.setShopCode(this.getLoginShopCode());
        room.setStatus(Integer.valueOf(1));
        ModelAndView mv = new ModelAndView("gc/room/edit");
        mv.addObject("room", room);
        mv.addObject("shopName", this.getTypeList("shopName"));
        mv.addObject("roomType", this.getTypeList("gcRoomType"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("room") GcRoom room) {
        if(this.chkNull(room.getShopCode())) {
            return this.getResult(false, "请选择门店");
        } else if(this.chkNull(room.getCode())) {
            return this.getResult(false, "请输入编号");
        } else if(this.chkNull(room.getChName())) {
            return this.getResult(false, "请输入名称");
        } else {
            if(this.chkNull(room.getStatus())) {
                room.setStatus(Integer.valueOf(1));
            }

            if(this.gcRoomDao.exists(new GcRoomPK(room.getShopCode(), room.getCode()))) {
                return this.getResult(false, "编号已存在");
            } else {
                room.setCreateUser(this.getLoginUserCode());
                room.setCreateTime(new Date());
                room.setUpdateTime(new Date());

                try {
                    this.gcRoomDao.add(room);
                    this.reloadTypeList("gcRoom");
                    this.addUserLog("新增教室", "门店:" + room.getShopCode() + ",编号:" + room.getCode() + ",名称:" + room.getChName());
                } catch (Exception var3) {
                    this.log.error("add gcroom", var3);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"edit"})
    public ModelAndView edit(@ModelAttribute("pk") GcRoomPK pk) {
        GcRoom room = (GcRoom)this.gcRoomDao.getById(pk);
        if(room == null) {
            return this.showAlert("没有这个教室");
        } else {
            ModelAndView mv = new ModelAndView("gc/room/edit");
            mv.addObject("room", room);
            mv.addObject("shopName", this.getTypeList("shopName"));
            mv.addObject("roomType", this.getTypeList("gcRoomType"));
            mv.addObject("_oper", "edit");
            return mv;
        }
    }

    @RequestMapping({"_edit"})
    @ResponseBody
    public String _edit(@ModelAttribute("room") GcRoom room) {
        if(this.chkNull(room.getShopCode())) {
            return this.getResult(false, "没有这个教室");
        } else if(this.chkNull(room.getCode())) {
            return this.getResult(false, "没有这个教室");
        } else if(this.chkNull(room.getChName())) {
            return this.getResult(false, "请输入名称");
        } else {
            if(this.chkNull(room.getStatus())) {
                room.setStatus(Integer.valueOf(1));
            }

            GcRoom room1 = this.gcRoomDao.getByCode(room.getShopCode(), room.getCode());
            if(room1 == null) {
                return this.getResult(false, "没有这个教室");
            } else {
                room1.setChName(room.getChName());
                room1.setPersonMax(room.getPersonMax());
                room1.setRoomType(room.getRoomType());
                room1.setNote(room.getNote());
                room1.setStatus(room.getStatus());
                room1.setUpdateTime(new Date());

                try {
                    this.gcRoomDao.update(room1);
                    this.reloadTypeList("gcRoom");
                    this.addUserLog("修改教室", "门店:" + room.getShopCode() + ",编号:" + room1.getCode() + ",名称:" + room1.getChName());
                } catch (Exception var4) {
                    this.log.error("edit gcroom", var4);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getResult(true, "保存完成");
            }
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@ModelAttribute("pk") GcRoomPK pk) {
        GcRoom room = (GcRoom)this.gcRoomDao.getById(pk);
        if(room == null) {
            return this.getResult(false, "没有这个教室");
        } else {
            try {
                this.gcRoomDao.updateStatus(room, 0);
                this.reloadTypeList("gcRoom");
                this.addUserLog("删除教室", "门店:" + room.getShopCode() + ",编号:" + room.getCode() + ",名称:" + room.getChName());
            } catch (Exception var4) {
                this.log.error("del gcroom", var4);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
